package king.loadProperties
{
	
	/*
	QQ: 334973991
	*/
	import king.MyDateLoader;
	public class LoadProperties
	{
		private static var loadProperties:LoadProperties;
		private var myDateLoader:MyDateLoader;
		private var map:Map=new Map();
		private var initFlag:Boolean=false;
		private var mapFunction:Map=new Map();
		private var getMapFlag:Boolean=false;
		private var _initSuccessHandle:Function;
		public static function getInstance(propertiesUrl:String):LoadProperties{
			if(loadProperties==null){
				loadProperties=new LoadProperties(propertiesUrl);
			}
			return loadProperties;
		}
		public function LoadProperties(propertiesUrl:String){
			this.myDateLoader=new MyDateLoader(this.completeHandle);
			this.myDateLoader.loadXml(propertiesUrl);
		}
		private function completeHandle(date:String):void{
			var dateArray:Array=date.split("\r\n");
			for(var i:uint=0;i<dateArray.length;i++){
				var str:String=dateArray[i];
				var index:uint=dateArray[i].indexOf("=");
				map.put(str.substring(0,index),str.substring(index+1,str.length));
			}
			var keys:Array=mapFunction.keys;
			for(var j:uint=0;j<keys.length;j++){
				var myfunction:Function=mapFunction.get(keys[j]) as Function;
				myfunction(map.get(keys[j]));
			}
			if(getMapFlag){
				_initSuccessHandle(map);
			}
			initFlag=true;
		}
		public function getUrl(urlName:String,initSuccessHandle:Function):void{
			if(initFlag){
				initSuccessHandle(map.get(urlName));
			}else{
				mapFunction.put(urlName,initSuccessHandle);
			}
		}
		public function getMap(initSuccessHandle:Function):void{
			if(initFlag){
				initSuccessHandle(map);
			}else{
				getMapFlag=true;
				_initSuccessHandle=initSuccessHandle;
			}
		}
		private function setParame():void{
			
		}
	}
}
